import java.util.*;

/**
 * @Description:
 * @Auther: zhang.jy
 * @Date: Created in 2019年06月10日 16:10
 * @Copyright wonhigh.cn
 */
public class reckon {
	public static void main(String[] args) {
		fangCheng();
	}

	public static void fangCheng() {

		//输入
		Scanner in = new Scanner(System.in);
		System.out.print("请输入数值：");
		int sum = in.nextInt();

		// aX + bY = sum  这个很重要
		// a 和 b,是斐波那契数列

		int maxShuLie = 1;
		while (true) {
			//斐波那契数列长度
			int fib = fib_map(maxShuLie);
			if (fib > sum) {
				break;
			}
			maxShuLie++;
		}
		Map<Integer,String> longMap = new HashMap<Integer, String>();
		//这里的顺利可以优化一下
		for (int shulie_long = 1; shulie_long < maxShuLie; shulie_long++) {
			for (int x = 1; x < sum; x++) {
				int aaa = fib_map(shulie_long) * x;
				if (aaa < sum) {
					//y=(sum - aX)/b;
					double y = (sum - fib_map(shulie_long) * x) / fib_map(shulie_long + 1);
					//判断y为整数
					boolean integer = isInteger(y);
					if (integer) {
						int yy = (int) y;
						System.out.println("数列长度: " + shulie_long);
						System.out.println("X:" + x + ",Y:" + yy);
						//保存相关信息
						longMap.put(shulie_long, "X:" + x + ",Y:" + yy);
					}
				}
			}
		}
		//找出最大值并打印
		System.out.println("==============结果==============");
		System.out.println("输入: " + sum);
		Set<Integer> longSet = longMap.keySet();
		Integer max = Collections.max(longSet);
		String s = longMap.get(max);
		System.out.println("初始化的值: " + s);
		String[] split = s.split(",");
		int x = Integer.parseInt(split[0].split(":")[1]);
		int y = Integer.parseInt(split[1].split(":")[1]);
		map.get(max);
		System.out.print(x + "," + y + ",");
		for (int i = 1; i <= max; i++) {
			int i1 = map.get(i) * x + map.get(i + 1) * y;
			System.out.print(i1+",");
		}
		System.out.println("最大长度:" + (max + 2));



	}

	//判断double是否为整数
	public static boolean isInteger(double d){
		return d % 1 ==0;
	}

	//计算斐波那契数列的值,这里应该有个算法优化的...
	public static int fib(int num) {
		//判断：是否是第一个数和第二个数
		if (num == 1 || num == 2) {
			return 1;
		} else {
			//循环调用本函数
			return fib(num - 2) + fib(num - 1);
		}
	}

	//可以将变量提出作为一个全局变量
	private static Map<Integer, Integer> map = new HashMap<Integer,Integer>();

	//可以用个常量保存前两个值...
	public static int fib_map(int num){
		if (map.get(num) != null) {
			return map.get(num);
		}
		map.put(1, 1);
		map.put(2, 1);
		for (int i = 3; i <= num; i++) {
			map.put(i, map.get(i - 1) + map.get(i - 2));
		}
		return map.get(num);
	}





	//test 二元一次方程
	public static void eryuanyicifangcheng () {
		/*
		 *      2x+2y=10
		 *      3x+4y=18
		 */
		double x,y;
//      double a1=2,b1=2,c1=10;
//      double a2=3,b2=4,c2=18;
		Scanner in=new Scanner(System.in);
		System.out.println("对照格式输入：a1X+b1Y=c1  a2X+b2Y=c2");
		System.out.print("请输入a1的值：");
		double a1=in.nextDouble();
		System.out.print("请输入b1的值：");
		double b1=in.nextDouble();
		System.out.print("请输入c1的值：");
		double c1=in.nextDouble();
		System.out.print("请输入a2的值：");
		double a2=in.nextDouble();
		System.out.print("请输入b2的值：");
		double b2=in.nextDouble();
		System.out.print("请输入c2的值：");
		double c2=in.nextDouble();
		double j,k,l;
		j=a2/a1;    //j==1.5
		a1=a1*j;    //a1==3
		b1=b1*j;    //b1==3
		c1=c1*j;    //c1==15
		k=c2-c1;
		l=b2-b1;
		y=k/l;
		x=(c2-b2*y)/a2;
		System.out.println("x="+x);
		System.out.println("y="+y);

	}


}
